/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.lang.Comparable;
import java.util.ArrayList;
/**
 *
 * Treat each course as a collection of time constraint.
 *
 * @author yzhang
 */
public class CourseDescriptor implements Comparable {
    public String classId;
    public int units;
    public int priority;
    private ArrayList durationList = new ArrayList();

    public CourseDescriptor(String classId, int units) {
        this.classId = classId;
        this.units = units;
        priority = units;
    }

    public void addTimePeriod(TimePeriod tp) {
        durationList.add(tp);
    }

    /**
     *
     * @param day       between 0 and 6, which matches days in a week s,m,t,w,th,fri,sat
     * @param start     start hour
     * @param end       end our
     */
    public void addTimePeriod(int day, float start, float end) {
        addTimePeriod( new TimePeriod(day, start, end));
    }

    public ArrayList getDurationList() {
        return durationList;
    }

    public boolean isConflicting(CourseDescriptor cd) {
        ArrayList otherList = cd.getDurationList();
        int si = durationList.size();
        int sj = otherList.size();
        TimePeriod tp;
        for(int i=0;i<si;i++) {
            tp = (TimePeriod) durationList.get(i);
            for(int j=0;j<sj;j++) {
                if(tp.isColliding((TimePeriod)otherList.get(j)))
                    return true;
            }
        }
        return false;
    }

    public int compareTo(Object o) {
        return priority - ((CourseDescriptor)o).priority;
    }

}
